<?php

namespace App\Http\Resources;

use Illuminate\Http\Request;

class StorageConfigResource extends BaseResource
{
    /**
     * Transform the resource into an array.
     *
     * @return array<string, mixed>
     */
    public function toArray(Request $request): array
    {
        return [
            'id' => $this->id,
            'type' => $this->type,
            'type_name' => $this->getTypeName(),
            'name' => $this->name,
            'is_default' => $this->is_default,
            'config' => $this->config,
            'status' => $this->status,
            'remark' => $this->remark,
            'created_at' => $this->formatDateTime($this->created_at),
            'updated_at' => $this->formatDateTime($this->updated_at),
        ];
    }

    /**
     * 获取类型名称
     *
     * @return string
     */
    protected function getTypeName(): string
    {
        $types = [
            \App\Models\StorageConfig::TYPE_LOCAL => '本地存储',
            \App\Models\StorageConfig::TYPE_ALIYUN_OSS => '阿里云OSS',
            \App\Models\StorageConfig::TYPE_TENCENT_COS => '腾讯云COS',
            \App\Models\StorageConfig::TYPE_QINIU => '七牛云',
        ];

        return $types[$this->type] ?? '未知';
    }
}

